package com.wangjiacai.utils.ali.asr;

import com.alibaba.nls.client.protocol.InputFormatEnum;
import com.alibaba.nls.client.protocol.SampleRateEnum;
import com.alibaba.nls.client.protocol.SpeechReqProtocol;
import com.alibaba.nls.client.transport.Connection;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;

@Slf4j
public class SpeechTranscriber extends SpeechReqProtocol {

    public String getFormat() {
        return (String)this.payload.get("format");
    }

    public void setFormat(InputFormatEnum format) {
        this.payload.put("format", format.getName());
    }

    public Integer getSampleRate() {
        return (Integer)this.payload.get("sample_rate");
    }

    public void setSampleRate(SampleRateEnum sampleRate) {
        this.payload.put("sample_rate", sampleRate.value);
    }

    public void setEnableIntermediateResult(boolean isEnable) {
        this.payload.put("enable_intermediate_result", isEnable);
    }

    public void setEnablePunctuation(boolean isEnable) {
        this.payload.put("enable_punctuation_prediction", isEnable);
    }

    public void setEnableITN(boolean enableITN) {
        this.payload.put("enable_inverse_text_normalization", enableITN);
    }

    public SpeechTranscriber(String appKey){
        this.payload = new HashMap();
        this.header.put("namespace", "SpeechTranscriber");
        this.header.put("name", "StartTranscription");
        this.setAppKey(appKey);
        this.setFormat(InputFormatEnum.PCM);
        this.setSampleRate(SampleRateEnum.SAMPLE_RATE_16K);
        this.setEnableIntermediateResult(false);
        this.setEnablePunctuation(true);
        this.setEnableITN(false);
    }
    public void setTaskId(String taskId){
        super.setTaskId(taskId);
    }

    public void setConnection(Connection connection) {
        this.conn=connection;
    }

}
